﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.IO;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;

namespace Organizer.Model.Movie.IMDb
{
    public class Movie
    {
        protected Movie() { }

        [Required]
        public int MovieId { get; set; }

        [Required]
        public string Name { get; set; }

        [Required]
        private byte[] _cover { get; set; }
        [NotMapped]
        public virtual Image Cover { 
            get { 
                using (var stream = new MemoryStream(_cover)) {
                    return System.Drawing.Image.FromStream(stream);
                }
            }
            set {
                MemoryStream stream = new MemoryStream();
                Cover.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                _cover = stream.ToArray();
            } 
        }

        [Required]
        public double Rating { get; set; }

        [Required]
        public int Year { get; set; }

        [Required]
        public string[] Genres { get; set; }

        [Required]
        public string[] Keywords { get; set; }

        [Required]
        public virtual List<Person> Directors { get; set; }

        [Required]
        public virtual List<Person> Writers { get; set; }

        [Required]
        public virtual List<CharacterPerson> Actors { get; set; }
    }
}
